

//
//  HomeViewController.m
//  Tee-Study
//
//  Created by DJtd on 16/9/20.
//  Copyright © 2016年 杨迎龙. All rights reserved.
//

#import "HomeViewController.h"
#import "OneTableViewCell.h"
#import "TwoTableViewCell.h"
#import "ThreeTableViewCell.h"

@interface HomeViewController ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *playDataSource;
@property (nonatomic, strong) NSMutableArray *readDataSource;

@end

@implementation HomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.navigationController.navigationBar.hidden = YES;
    
    self.playDataSource = [NSMutableArray arrayWithCapacity:0];
    self.readDataSource = [NSMutableArray arrayWithCapacity:0];
//    UIBarButtonItem *item1 = CreatBarButton(@"1", searchBtnAction);
//    UIBarButtonItem *item2 = CreatBarButton(@"2", loadBtnAction);
//    UIBarButtonItem *item3 = CreatBarButton(@"3", problemBtnAction);
//    UIBarButtonItem *item4 = CreatBarButton(@"4", writeBtnAction);
//    UIBarButtonItem *item5 = CreatBarButton(@"5", scanBtnAction);
//    self.navigationItem.rightBarButtonItems = @[item5,item4,item3,item2,item1];
    
    [self creatTopView];
    [self creatTableView];

    
    
    
 
    
}


- (void)creatTopView {
    
    UIView *topView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 64)];
    [self.view addSubview:topView];
    topView.backgroundColor = BlueColor;
    
    UIButton *searchBtn = CreatButton;
    [searchBtn setImage:[[UIImage imageNamed:@"1"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    [searchBtn addTarget:self action:@selector(searchBtnAction) forControlEvents:UIControlEventTouchUpInside];
    searchBtn.frame = CGRectMake(ScreenWidth - 125, 32, 20, 20);
    
    
    
    UIButton *loadBtn = CreatButton;
    [loadBtn setImage:[[UIImage imageNamed:@"2"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    [loadBtn addTarget:self action:@selector(loadBtnAction) forControlEvents:UIControlEventTouchUpInside];
    loadBtn.frame = CGRectMake(ScreenWidth - 100, 32, 20, 20);

    UIButton *problemBtn = CreatButton;
    [problemBtn setImage:[[UIImage imageNamed:@"3"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    [problemBtn addTarget:self action:@selector(problemBtnAction) forControlEvents:UIControlEventTouchUpInside];
    problemBtn.frame = CGRectMake(ScreenWidth - 75, 32, 20, 20);

    UIButton *writeBtn = CreatButton;
    [writeBtn setImage:[[UIImage imageNamed:@"4"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    [writeBtn addTarget:self action:@selector(writeBtnAction) forControlEvents:UIControlEventTouchUpInside];
    writeBtn.frame = CGRectMake(ScreenWidth - 50, 32, 20, 20);

    UIButton *scanBtn = CreatButton;
    [scanBtn setImage:[[UIImage imageNamed:@"5"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    [scanBtn addTarget:self action:@selector(scanBtnAction) forControlEvents:UIControlEventTouchUpInside];
    scanBtn.frame = CGRectMake(ScreenWidth - 25, 32, 20, 20);

    CustomImageView *logoImg = [[CustomImageView alloc] initWithFrame:CGRectMake(5, 27, 40, 30) imageName:@"logo"];
    logoImg.contentMode = UIViewContentModeScaleAspectFit;
    UILabel *titileLabel = [[UILabel alloc] initWithFrame:CGRectMake(45, 27, 100, 30)];
    titileLabel.text = @"腾云教育";
    titileLabel.textColor = [UIColor whiteColor];
    titileLabel.font = [UIFont systemFontOfSize:20];
    
    [topView addSubview:titileLabel];
    [topView addSubview:searchBtn];
    [topView addSubview:loadBtn];
    [topView addSubview:problemBtn];
    [topView addSubview:writeBtn];
    [topView addSubview:scanBtn];
    [topView addSubview:logoImg];
    
    
//    self.navigationItem.titleView = topView;
}



- (void)creatTableView {
    //    150+605= 755   !100
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, ScreenWidth, ScreenHeight - 64) style:UITableViewStylePlain];
    [self.view addSubview:self.tableView];
    
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.showsVerticalScrollIndicator = NO;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    UINib *nib = [UINib nibWithNibName:@"OneTableViewCell" bundle:nil];
    [self.tableView registerNib:nib forCellReuseIdentifier:@"OneCell"];
    [self.tableView registerClass:[TwoTableViewCell class] forCellReuseIdentifier:@"TwoTableViewCell"];
    UINib *nib2 = [UINib nibWithNibName:@"ThreeTableViewCell" bundle:nil];
    [self.tableView registerNib:nib2 forCellReuseIdentifier:@"ThreeCell"];

//    [self creatNextButton];
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 0) {
        return 40;
    } else if (indexPath.row == 1) {
        return 100;
    } else if (indexPath.row == 2) {
        return 40;
    }
    return 60;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return ScreenHeight/4;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight/4)];
    view.backgroundColor = [UIColor redColor];
    return view;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 3;
    //    return self.readDataSource.count + 3;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    OneTableViewCell *oneCell = [tableView cellForRowAtIndexPath:indexPath];
    TwoTableViewCell *twoCell = [tableView cellForRowAtIndexPath:indexPath];
    ThreeTableViewCell *threeCell = [tableView cellForRowAtIndexPath:indexPath];
    if (!oneCell) {
        oneCell = [[OneTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"OneCell"];
    }
    if (!twoCell) {
        twoCell = [[TwoTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"TwoTableViewCell"];
    }
    if (!threeCell) {
        threeCell = [[ThreeTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"ThreeCell"];
    }
    
    switch (indexPath.row) {
        case 0:
            
            
            
            return oneCell;
            break;
            
        case 1:
            
            
            return twoCell;
            break;
            
        case 2:
            
            oneCell.label.text = @"文档资料";
            return oneCell;
            break;
            
        default:
            break;
    }
    
    
    
    return threeCell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}



















/**
 *  导航栏右侧5个按钮跳转
 */
- (void)searchBtnAction {
    NSLog(@"1");
    Button_1_ViewController *_1vc = [[Button_1_ViewController alloc] init];
    [self.navigationController pushViewController:_1vc animated:YES];
}

- (void)loadBtnAction {
    NSLog(@"2");
    Button_2_ViewController *_2vc = [[Button_2_ViewController alloc] init];
    [self.navigationController pushViewController:_2vc animated:YES];
}

- (void)problemBtnAction {
    NSLog(@"3");
    Button_3_ViewController *_3vc = [[Button_3_ViewController alloc] init];
    [self.navigationController pushViewController:_3vc animated:YES];
}

- (void)writeBtnAction {
    NSLog(@"4");
    Button_4_ViewController *_4vc = [[Button_4_ViewController alloc] init];
    [self.navigationController pushViewController:_4vc animated:YES];
}

- (void)scanBtnAction {
    NSLog(@"5");
    Button_5_ViewController *_5vc = [[Button_5_ViewController alloc] init];
    [self.navigationController pushViewController:_5vc animated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}
@end














